<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>15-3 给对象添加iterator属性让他支持for...of循环（具备数组结构）</title>
</head>

<body>
  <script>
    let obj = {
      0: 10,
      1: 20,
      2: 30,
      length: 3,
      // [Symbol.iterator]() {
      //   let self = this, index = 0;
      //   return {
      //     next() {
      //       return index >= self.length
      //         ? {
      //           done: true,
      //           value: 'undefined'
      //         }
      //         : {
      //           done: false,
      //           value: self[index++]
      //         }
      //     }
      //   }
      // }
      [Symbol.iterator]: Array.prototype[Symbol.iterator]
    }
    for (let value of obj) {
      console.log(value)
    }
  </script>
</body>

</html>